// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.
#pragma once

#include "ccf/http_consts.h"
#include "ccf/http_header_map.h"
#include "ccf/odata_error.h"

#include <functional>

namespace ccf::http
{
  class HTTPResponder
  {
  public:
    virtual ~HTTPResponder() = default;

    virtual bool send_response(
      http_status status_code,
      http::HeaderMap&& headers,
      http::HeaderMap&& trailers,
      std::vector<uint8_t>&& body) = 0;

    bool send_odata_error_response(ccf::ErrorDetails&& error)
    {
      nlohmann::json body = ccf::ODataErrorResponse{
        ccf::ODataError{std::move(error.code), std::move(error.msg), {}}};
      const std::string s = body.dump();
      std::vector<uint8_t> v(s.begin(), s.end());

      http::HeaderMap headers;
      headers[http::headers::CONTENT_TYPE] =
        http::headervalues::contenttype::JSON;

      return send_response(error.status, std::move(headers), {}, std::move(v));
    }
  };
}
